package com.msb.provider.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sunpeng
 * @Date 2021-08-11 15:55
 */

@Configuration
public class RabbitmqConfig {

    @Bean
    protected Queue queue(){
        return new Queue("myQueue");
    }

    @Bean
    public Queue queue1(){
        return new Queue("myfanout1");
    }

    @Bean
    public Queue queue2(){
        return new Queue("myfanout2");
    }

    @Bean
    public FanoutExchange getFanoutExchange(){
        return new FanoutExchange("amq.fanout");
    }

    @Bean
    public Binding binding(Queue queue1, FanoutExchange getFanoutExchange){
        return BindingBuilder.bind(queue1).to(getFanoutExchange);
    }

    @Bean
    public Binding binding2(Queue queue2, FanoutExchange getFanoutExchange){
        return BindingBuilder.bind(queue2).to(getFanoutExchange);
    }

    @Bean
    public Queue topicQueue1(){
        return new Queue("topicQueue1");
    }

    @Bean
    public Queue topicQueue2(){
        return new Queue("topicQueue2");
    }

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("amq.topic");
    }

    @Bean
    public Binding bindingTopic1(Queue topicQueue1, TopicExchange topicExchange){
        return BindingBuilder.bind(topicQueue1).to(topicExchange).with("com.msb.*");
    }

    @Bean
    public Binding bindingTopic2(Queue topicQueue2, TopicExchange topicExchange){
        return BindingBuilder.bind(topicQueue2).to(topicExchange).with("com.msb.a");
    }

}
